 

 class AssetsUtil{

    private constructor() {
    }

  
    private static _ins:AssetsUtil
    static ins(){
        if(!this._ins) {
            this._ins =  new AssetsUtil()
        } 
        return this._ins;
    }


    loadImage = (url:string | string[]) => {
        if (!Array.isArray(url)) {
        return this.loadOneImage(url);
         }

        const loaders = url.map(url => this.loadOneImage(url));
         return Promise.all(loaders)
        }

    loadOneImage = (url) => {
    return new Promise((resolve : (value: egret.Bitmap) => void, reject) => {
        const onImageLoaded = (e: egret.Event) => {
            const imageLoader: egret.ImageLoader = e.currentTarget;
            const bitmapData: egret.BitmapData = imageLoader.data;
            const texture = new egret.Texture();
            texture._setBitmapData(bitmapData);
            const bitmap = new egret.Bitmap(texture);


            resolve(bitmap)
        }

        const imageLoader = new egret.ImageLoader();
        imageLoader.crossOrigin = "anonymous";
        imageLoader.once(egret.Event.COMPLETE, onImageLoaded, this);
        imageLoader.load(url);
    })
}

 

}